/* JSDAS
* Copyright (C) 2008-2009 Bernat Gel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


var getCoordinateSystems = function(url) {
	
	JSDAS.Demo.setStatus("Loading Coordinate Systems...", false);
	document.getElementById('results_content').innerHTML = '<img src="../resources/images/wait.gif">';
	JSDAS.coordinate_systems(url, processCoordinateSystems);
}

var processCoordinateSystems = function(response) {
	JSDAS.Demo.setStatus("Coordinate Systems Received... Processing starts", false);

	//We'v got the sources and we're done with DAS. Now, just do something with them
	var results_div = document.getElementById('results_content');

	var table = "";

	//check if the query was done using the new rows parameter
	if(response.total && response.start && response.end) {
	    table += "Showing Coordinate Systems "+response.start+" to "+response.end+" of "+response.total+" total.<br><br>";
	}
	
	var coord_sys = response.COORDINATES;
	table += '<table class="results">';
	table += '<thead><tr><th>URI</th><th>TaxId</th><th>Source</th><th>Authority</th><th>Test Range</th></tr></thead>';
	table += '<tbody>';
	for(var i=0, l=coord_sys.length; i<l; ++i) {
	    var s = coord_sys[i];
	    table += '<tr>';
	    table += '<td>'+(s.uri)+'</td>';
	    table += '<td>'+(s.taxid || '')+'</td>';
	    table += '<td>'+(s.source || '')+'</td>';
	    table += '<td>'+(s.authority || '')+'</td>';
	    table += '<td>'+(s.test_tange || '')+'</td>';
	    table +='</tr>';
	}
	table += '</tbody>';
	table += '</table>';
	
	results_div.innerHTML = table;
	JSDAS.Demo.setStatus("Done");
}

